package com.nbsaas.boot.controller.evaluate;

import com.nbsaas.boot.evaluate.api.apis.EvaluateApi;
import com.nbsaas.boot.evaluate.api.domain.request.EvaluateRequest;
import com.nbsaas.boot.evaluate.api.domain.request.EvaluateSearch;
import com.nbsaas.boot.evaluate.api.domain.response.EvaluateResponse;
import com.nbsaas.boot.evaluate.api.domain.simple.EvaluateSimple;
import com.nbsaas.boot.evaluate.ext.apis.EvaluateExtApi;
import com.nbsaas.boot.evaluate.ext.domain.request.EvaluateExtRequest;
import com.nbsaas.boot.rest.annotations.*;
import com.nbsaas.boot.rest.enums.StoreState;
import com.nbsaas.boot.rest.response.ListResponse;
import com.nbsaas.boot.rest.response.PageResponse;
import com.nbsaas.boot.rest.response.ResponseObject;
import jakarta.annotation.Resource;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 评价控制器
 */
@RequiresAuthentication
@RestController
@RequestMapping("/evaluate")
public class EvaluateController {


    @Resource
    private EvaluateApi evaluateApi;


    @Resource
    private EvaluateExtApi evaluateExtApi;

    @CreateData
    @PostMapping("/createExt")
    public ResponseObject<?> createExt(@RequestBody EvaluateExtRequest request) {
        return evaluateExtApi.createExt(request);
    }

    /**
     * 搜索数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("evaluate:search")
    @PostMapping("/search")
    public PageResponse<EvaluateSimple> search(@RequestBody EvaluateSearch request) {
        request.setStoreState(StoreState.normal);
        return evaluateApi.search(request);
    }

    /**
     * 列表数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("evaluate:list")
    @PostMapping("/list")
    public ListResponse<EvaluateSimple> list(@RequestBody EvaluateSearch request) {
        request.setStoreState(StoreState.normal);
        return evaluateApi.list(request);
    }

    /**
     * 添加数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("evaluate:create")
    @CreateData
    @PostMapping("/create")
    public ResponseObject<EvaluateResponse> create(@RequestBody @Validated(AddOperator.class) EvaluateRequest request) {
        return evaluateApi.create(request);
    }

    /**
     * 修改数据
     *
     * @param request
     * @return
     */
    @RequiresPermissions("evaluate:update")
    @UpdateData
    @PostMapping("/update")
    public ResponseObject<EvaluateResponse> update(@RequestBody @Validated(UpdateOperator.class) EvaluateRequest request) {
        return evaluateApi.update(request);
    }

    /**
     * 删除数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("evaluate:delete")
    @PostMapping("/delete")
    public ResponseObject<?> delete(@RequestBody @Validated(DeleteOperator.class) EvaluateRequest request) {
        return evaluateApi.delete(request);
    }

    /**
     * 查看数据
     *
     * @param request
     * @return
     */
    @SearchData
    @RequiresPermissions("evaluate:view")
    @PostMapping("/view")
    public ResponseObject<EvaluateResponse> view(@RequestBody @Validated(ViewOperator.class) EvaluateRequest request) {
        return evaluateApi.view(request);
    }
}